# coding=utf-8

import os
import web

from hooks import load_hook, unload_hook
from controllers.admin import app_admin
from controllers.holiday import app_holiday

# 配置网站的根路径
# 尝试解决web.seeother跳转不从根路径开始的问题
_root = ''
os.environ["SCRIPT_NAME"] = _root
os.environ["REAL_SCRIPT_NAME"] = _root

urls = (
    # === 测试 ===
    '/test/uYk', 'controllers.test.views.uYk',
    '/test/uYk/(\d+)', 'controllers.test.views.uYk',
    '/test/uYk/success/(\d+)', 'controllers.test.views.uYk_success',

    # === 灵感 ===
    '/afflatus/waterfall/(\d+)', 'controllers.afflatus.views.Waterfall',
    # 灵感详页
    '/afflatus/(\d+)', 'controllers.afflatus.views.Detail',
    # 灵感分享页
    # 关注灵感后触发
    '/afflatus/share/(\d+)', 'controllers.afflatus.views.Share',
    # 通过灵感邀请的用户
    # 关注灵感信息分享微博中的链接
    '/afflatus/invite/(\d+)', 'controllers.afflatus.views.Invite',
    # 灵感信息的“去过”功能
    '/afflatus/beento/(\d+)', 'controllers.afflatus.views.BeenTo',

    # === 特惠信息 ===
    '/discounts', 'controllers.discounts.views.Index',
    '/discounts/rss', 'controllers.discounts.views.RSS',
    '/discounts/(\d+)', 'controllers.discounts.views.Detail',
    '/discounts/(\w+)', 'controllers.discounts.views.Index',
    '/discounts/redirect/(\d+)', 'controllers.discounts.views.Redirect',
    # === Ajax Command ===
    '/async-cmd/(\w+)', 'controllers.common.views.AjaxCommand',

    # === 首页 ===
    '[/]', 'controllers.common.views.Index',

    # === 用户 ===
    # 登录
    '/login', 'controllers.users.views.Login',
    # 登出
    '/logout', 'controllers.users.views.Logout',
    # 社交连接
    '/connect/(\w+)', 'controllers.users.views.SocialConnect',
    # 订阅
    '/subscribe', 'controllers.users.views.Subscribe',
    # 订阅登录
    '/subscribe/login', 'controllers.users.views.SubscribeLogin',
    '/register', 'controllers.users.views.Register',
    # 重置密码
    '/reset-password', 'controllers.users.views.ResetPassword',
    # 退订
    '/unsubscribe', 'controllers.users.views.Unsubscribe',

    # === 帮助 ===
    # 关于我们
    '/help/([\w\-]+)', 'controllers.common.views.Help',
    
    # 后台管理
    '/admin', app_admin,
    # 节日祝福
    '/holiday', app_holiday,
)

xunbaotu = web.application(urls, locals())
# processor
xunbaotu.add_processor( web.loadhook( load_hook ) )
xunbaotu.add_processor( web.unloadhook( unload_hook ) )

